//
//  ViewController.swift
//  DataStructureWH
//
//  Created by 王涵 on 2019/10/19.
//  Copyright © 2019 王涵. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    
    let tableView = UITableView()
    let tableViewText = ["堆栈（数组实现)","堆栈（链表实现）","队列（数组实现）","队列（链表实现）","搜索排序列表","二叉搜索树","比较排序算法","最短路径"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.navigationBar.barTintColor = blueColor
        tableView.frame = self.view.frame
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorColor = UIColor.clear//分割线颜色
//        self.title = "数据结构交互式学习工具IOS版"
         self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]//设置导航栏上标题颜色
    }
    override func viewDidDisappear(_ animated: Bool) {
        self.tableView.removeFromSuperview()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        self.view.addSubview(tableView)
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableViewText.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = HomeTableViewCell(style:UITableViewCell.CellStyle.default, reuseIdentifier: "cell")
        cell.textLabel?.text = tableViewText[indexPath.row]
        cell.selectionStyle = UITableViewCell.SelectionStyle.none
        return cell
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let vi = UIView()
        return vi
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath[1] {
        case 0:
           navigationPushView(vi:ArrayImplementaion())
//            let kAppdelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
//                       let rotation : UIInterfaceOrientationMask = [.landscapeLeft, .landscapeRight]
//                       kAppdelegate?.blockRotation = rotation
//                       navigationPushView(vi: ComparisonSortingAlgorithms())
        case 1:
            navigationPushView(vi:LinkedListImplementaion())
        case 2:
            navigationPushView(vi: ArrayIm())
        case 3:
            navigationPushView(vi:  LinkedList())
        case 4:
            navigationPushView(vi:SearchingSortedList())
        case 5:
            navigationPushView(vi: BinarySearchTreeC())
        case 6:
            let kAppdelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
            let rotation : UIInterfaceOrientationMask = [.landscapeLeft, .landscapeRight]
            kAppdelegate?.blockRotation = rotation
            navigationPushView(vi: ComparisonSortingAlgorithms())
        default:
             navigationPushView(vi: DijkstraShortestPathC())
        }
        
    }
    
    func navigationPushView(vi:UIViewController){
        vi.modalPresentationStyle = .fullScreen
        self.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(vi, animated: true)
        self.hidesBottomBarWhenPushed = false
    }
}

